 package edu.gdcc.linearList.stack;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import org.omg.CosNaming.NamingContextExtPackage.StringNameHelper;

public class ReverseWord { 
	private String input;
	private String output;
	
	public ReverseWord(String input) {
		this.input = input;
		this.output = "";
	}
	public String reverse() {
		int length = input.length();
		StackXUpgrade stack = new StackXUpgrade(length);
		for(int i = 0;i < length;i++){
			stack.push(input.charAt(i));
		}
		while(!stack.isEmpty()){
			output += String.valueOf(stack.pop());
		}
//		char[] cs = input.toCharArray();
		return output;
	}
	public static void main(String[] args) throws IOException {
		String input,output;
		while(true){
			System.out.println("Enter a string:");
			System.out.flush();
			input = getString();
			if(input.equals("")){
				break;
			}
			ReverseWord reverseWordApp = new ReverseWord(input);
			System.out.println(reverseWordApp.reverse());
		}
	}
	public static String getString() throws IOException {
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		String output = br.readLine();
		return output;
	}
}
